#ifndef STRING_BUILDER_H
#define STRING_BUILDER_H

#include <string>
#include <sstream>

template <typename T>
class VPHelper {
public:
	static void f( std::ostringstream& oss, const T& v ) {
		oss << v;
	}
};

template <typename T>
class VPHelper<T*> {
public:
	static void f( std::ostringstream& oss, const T* v ) {
		oss << "(adr:";
		if(v != NULL) {
			oss << v;
		} else {
			oss << "NULL";
		}
		oss << ")";
	}
};

class StringBuilder {
private:
	std::ostringstream oss;
	static std::string makeNewline();

public:
	static const std::string newline;

	template <typename T>
	StringBuilder& operator<<(const T& v) {
		VPHelper<T>::f(oss, v);
		return *this;
	}

	StringBuilder& operator<<(bool v) {
		oss << (v ? "true" : "false");
		return *this;
	}

	operator const std::string() const {
		return oss.str();
	}
};

#endif //STRING_BUILDER_H
